home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gcc_260.zip / gcc_260 / fixinc.dgux < prev    next >
Text File  |  1994-05-26  |  5KB  |  185 lines

  1. #!/bin/sh
  2. #
  3. # modified for dgux by hassey@dg-rtp.dg.com based on
  4. #
  5. #   fixinc.svr4  written by Ron Guilmette (rfg@ncd.com).
  6. #
  7. # This file is part of GNU CC.
  8. # GNU CC is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. # GNU CC is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU CC; see the file COPYING.  If not, write to
  18. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. #
  20. #
  21. #    See README-fixinc for more information.
  22.  
  23. # Directory containing the original header files.
  24. INPUT=${2-${INPUT-/usr/include}}
  25.  
  26. # Fail if no arg to specify a directory for the output.
  27. if [ x$1 = x ]
  28. then echo fixincludes: no output directory specified
  29. exit 1
  30. fi
  31.  
  32. # Directory in which to store the results.
  33. LIB=${1?"fixincludes: output directory not specified"}
  34.  
  35. # Make sure it exists.
  36. if [ ! -d $LIB ]; then
  37.   mkdir $LIB || exit 1
  38. fi
  39.  
  40. ORIG_DIR=`pwd`
  41.  
  42. # Make LIB absolute if it is relative.
  43. # Don't do this if not necessary, since may screw up automounters.
  44. case $LIB in
  45. /*)
  46.     ;;
  47. *)
  48.     cd $LIB; LIB=`${PWDCMD-pwd}`
  49.     ;;
  50. esac
  51.  
  52. echo 'Building fixincludes in ' ${LIB}
  53.  
  54. # Determine whether this filesystem has symbolic links.
  55. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  56.   rm -f $LIB/ShouldNotExist
  57.   LINKS=true
  58. else
  59.   LINKS=false
  60. fi
  61.  
  62. echo 'Making directories:'
  63. cd ${INPUT}
  64. if $LINKS; then
  65.   files=`ls -LR | sed -n s/:$//p`
  66. else
  67.   files=`find . -type d -print | sed '/^.$/d'`
  68. fi
  69. for file in $files; do
  70.   rm -rf $LIB/$file
  71.   if [ ! -d $LIB/$file ]
  72.   then mkdir $LIB/$file
  73.   fi
  74. done
  75.  
  76. # treetops gets an alternating list
  77. # of old directories to copy
  78. # and the new directories to copy to.
  79. treetops="${INPUT} ${LIB}"
  80.  
  81. if $LINKS; then
  82.   echo 'Making internal symbolic directory links'
  83.   for file in $files; do
  84.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  85.     if [ "$dest" ]; then    
  86.       cwd=`pwd`
  87.       # In case $dest is relative, get to $file's dir first.
  88.       cd ${INPUT}
  89.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  90.       # Check that the target directory exists.
  91.       # Redirections changed to avoid bug in sh on Ultrix.
  92.       (cd $dest) > /dev/null 2>&1
  93.       if [ $? = 0 ]; then
  94.     cd $dest
  95.     # X gets the dir that the link actually leads to.
  96.     x=`pwd`
  97.     # If link leads back into ${INPUT},
  98.     # make a similar link here.
  99.     if expr $x : "${INPUT}/.*" > /dev/null; then
  100.       # Y gets the actual target dir name, relative to ${INPUT}.
  101.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  102.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  103.       dots=`echo "$file" |
  104.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  105.       echo $file '->' $dots$y ': Making link'
  106.       rm -fr ${LIB}/$file > /dev/null 2>&1
  107.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  108.     else
  109.       # If the link is to outside ${INPUT},
  110.       # treat this directory as if it actually contained the files.
  111. # This line used to have $dest instead of $x.
  112. # $dest seemed to be wrong for links found in subdirectories
  113. # of ${INPUT}.  Does this change break anything?
  114.       treetops="$treetops $x ${LIB}/$file"
  115.     fi
  116.       fi
  117.       cd $cwd
  118.     fi
  119.   done
  120. fi
  121.  
  122. # Completely replace <_int_varargs.h> with a file that defines
  123. # va_list and gnuc_va_list
  124.  
  125. file=_int_varargs.h
  126. if [ -r ${INPUT}/$file ]; then
  127.   echo Replacing $file
  128.   cat > ${LIB}/$file << EOF
  129. /* This file was generated by fixinc.dgux.  */
  130. #ifndef __INT_VARARGS_H
  131. #define __INT_VARARGS_H
  132.  
  133. #if defined(__m88k__) && defined (__DGUX__)
  134. #ifndef __GNUC_VA_LIST
  135. #define __GNUC_VA_LIST
  136. typedef struct
  137. {
  138.   int  __va_arg;        /* argument number */
  139.   int *__va_stk;        /* start of args passed on stack */
  140.   int *__va_reg;        /* start of args passed in regs */
  141. } __gnuc_va_list;
  142. #endif /* not __GNUC_VA_LIST */
  143. #endif /* 88k && dgux */
  144.  
  145. #ifndef _VA_LIST_
  146. #define _VA_LIST_
  147. typedef __gnuc_va_list va_list;
  148. #endif /* _VA_LIST_ */
  149.  
  150. #endif /* __INT_VARARGS_H */
  151.  
  152. EOF
  153.   chmod a+r ${LIB}/$file
  154. fi
  155.  
  156. echo 'Removing unneeded directories:'
  157. cd $LIB
  158. files=`find . -type d -print | sort -r`
  159. for file in $files; do
  160.   rmdir $LIB/$file > /dev/null 2>&1
  161. done
  162.  
  163. if $LINKS; then
  164.   echo 'Making internal symbolic non-directory links'
  165.   cd ${INPUT}
  166.   files=`find . -type l -print`
  167.   for file in $files; do
  168.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  169.     if expr "$dest" : '[^/].*' > /dev/null; then    
  170.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  171.       if [ -f $target ]; then
  172.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  173.       fi
  174.     fi
  175.   done
  176. fi
  177.  
  178. cd ${ORIG_DIR}
  179.  
  180. exit 0
  181.  
  182.